package com.bjpowernode.mapstruct.one;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
@Mapper
public interface StudentConvert {
    StudentConvert convert = Mappers.getMapper(StudentConvert.class);
    StudentDto toStudentDto(Student student);

    @Mappings({
            @Mapping(source = "name",target="studentName"),
            @Mapping(source="age",target="studentAge"),
            @Mapping(source="sex",target="studentSex",qualifiedByName="tranSex"),
            @Mapping(source="create",target="createDate",dateFormat = "yyyy-MM-dd HH:mm:ss")
    })
    StudentC toStudentC(Student student);
    @Named("tranSex")
    default String tranSex(String sex){
        if("m".equals(sex)){
            return "男";
        }else if("f".equals(sex)){
            return "女";
        }else{
            return "未知";
        }
    }
}
